package com.united.ucts.modules.monitor.pojo;

import cn.hutool.core.util.NumberUtil;
import com.united.frame.common.module.pojo.dto.BaseDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;

/**
 * 自定义的服务器内存信息类
 *
 * @author hudan
 * @version 1.0
 * @filename Memory.java
 * @copyright www.united.com
 * @date 2019/7/22
 */
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class Memory extends BaseDto {

    @ApiModelProperty(value = "内存总量")
    private double total;
    @ApiModelProperty(value = "已用内存")
    private double used;
    @ApiModelProperty(value = "剩余内存")
    private double free;
    @ApiModelProperty(value = "jvm 内存总量")
    private double jvmTotal;
    @ApiModelProperty(value = "jvm 已使用")
    private double jvmUsed;
    @ApiModelProperty(value = "jvm 空余")
    private double jvmFree;

    public double getTotal() {
        return NumberUtil.div(total, (1024 * 1024 * 1024), 2);
    }

    public double getUsed() {
        return NumberUtil.div(used, (1024 * 1024 * 1024), 2);
    }

    public double getFree() {
        return NumberUtil.div(free, (1024 * 1024 * 1024), 2);
    }

    public double getUsage() {
        return NumberUtil.mul(NumberUtil.div(used, total, 4), 100);
    }

    public double getJvmUsage() {
        return NumberUtil.mul(NumberUtil.div(jvmTotal - jvmFree, jvmTotal, 4), 100);
    }

    public double getJvmTotal() {
        return NumberUtil.div(jvmTotal, (1024 * 1024), 2);
    }

    public double getJvmUsed() {
        return NumberUtil.div(jvmTotal - jvmFree, (1024 * 1024), 2);
    }

    public double getJvmFree() {
        return NumberUtil.div(jvmFree, (1024 * 1024), 2);
    }
}